<template>
	<!-- <div @touchmove.stop.prevent="moveHandle">
		<u-popup :show="show" mode="center" zIndex='99' :duration="100">
			<view class="box-tk" v-if="infoObj">
				<view class="view1">
					<view class="">{{infoObj.empid}}</view>
					<view class="view1-title">双签</view>
					<view class="">{{infoObj.name}}</view>
				</view>
				<view class="xian"></view>
				<scroll-view scroll-y="true" v-if="list.children"
					:class="['box-xis',list.children.length > 3 ? 'box-aigicon':'']">
					<view class="xis-title" v-for="(el,index) in list.children" :key="index">
						{{el.remark + ' ' + el.many +'.0' + el.packunit.trim() + ' ' + (el.dosage.trim() ? '【'+el.dosage+'】' : el.dosage)}}
					</view>
					<view class="box-img"></view>
					<view class="xis-hend" :class="[list.children.length>1 ? 'xis-avicon' :'']">
						<view class="" v-if="putongkoufu">
							<u-radio-group v-model="value" placement="row" activeColor="#7AD9DF !important"
								inactiveColor="#B0E9EC  !important">
								<u-radio :customStyle="{padding: '10px 0'}" v-for="(item, index) in radiolist"
									:key="index" :label="item.name" :name="item.name" @change="radioChange(item.id)"
									:class="value==item.name?'clao':'clat'">
								</u-radio>
							</u-radio-group>
							<view class="xis-yuanyin" v-if="yuanyinValue">
								<Select class="SelectList" :disabled="false" v-model="examinationTypeIndex"
									:options="teshuarray" @change="Selectchange"></Select>
								<u-textarea class="box-text" placeholder="请输入原因" maxlength="-1" v-model="yuanyin2"
									confirmType="done" :disabled="textBled"></u-textarea>
							</view>
						</view>
						<view class="hend-title">
							<text style="width: 65px;">用户名：</text>
							<u-input v-model="value2" placeholder="请输入工号" @change="change"></u-input>
							<view class="" style="width:90px;">
								<u-input v-model="value3" :disabled="true"></u-input>
							</view>
						</view>
						<view class="hend-title" style="padding:0 10px 10px;">
							<text class="text">时间：</text>
							<dateTimePickerSync class="hend-time" :placeholder="placeholder" mode="datetime"
								@TimePicker="TimePicker">
							</dateTimePickerSync>
						</view>
					</view>
				</scroll-view>
				<view class="tk-heard" v-if="list.children">
					<u-button type="primary" style="margin-right: 10px;" text="确认" class="btn" color="#82ECC3"
						@tap="StopImplement"></u-button>
					<u-button type="primary" text="取消" class="btn" color="#FF6E91" @tap="cancel"></u-button>
				</view>
			</view>
		</u-popup>
	</div> -->

	<uni-popup ref="popup" type="dialog" :mask-click="false">

		<view class="box-tk" v-if="infoObj">
			<view class="view1">
				<view class="">{{infoObj.empid}}</view>
				<view class="view1-title">双签</view>
				<view class="">{{infoObj.name}}</view>
			</view>
			<view class="xian"></view>
			<scroll-view scroll-y="true" v-if="list.children"
				:class="['box-xis',list.children.length > 3 ? 'box-aigicon':'']">
				<view class="xis-title" v-for="(el,index) in list.children" :key="index">
					{{el.remark + ' ' + el.many +'.0' + el.packunit.trim() + ' ' + (el.dosage.trim() ? '【'+el.dosage+'】' : el.dosage)}}
				</view>
				<view class="box-img"></view>
				<view class="xis-hend" :class="[list.children.length>1 ? 'xis-avicon' :'']">
					<view class="" v-if="putongkoufu">
						<u-radio-group v-model="value" placement="row" activeColor="#7AD9DF !important"
							inactiveColor="#B0E9EC  !important">
							<u-radio :customStyle="{padding: '10px 0'}" v-for="(item, index) in radiolist" :key="index"
								:label="item.name" :name="item.name" @change="radioChange(item.id)"
								:class="value==item.name?'clao':'clat'">
							</u-radio>
						</u-radio-group>
						<view class="xis-yuanyin" v-if="yuanyinValue">
							<Select class="SelectList" :disabled="false" v-model="examinationTypeIndex"
								:options="teshuarray" @change="Selectchange"></Select>
							<u-textarea class="box-text" placeholder="请输入原因" maxlength="-1" v-model="yuanyin2"
								confirmType="done" :disabled="textBled"></u-textarea>
						</view>
					</view>
					<view class="hend-title">
						<text>用户名：</text>
						<u-input v-model="value2" placeholder="请输入工号" @change="change"></u-input>
						<view class="" style="width:90px;">
							<u-input v-model="value3" :disabled="true"></u-input>
						</view>
					</view>
					<view class="hend-title" style="padding:0 10px 10px;">
						<text class="text">时间：</text>
						<dateTimePickerSync class="hend-time" :placeholder="placeholder" mode="datetime"
							@TimePicker="TimePicker">
						</dateTimePickerSync>
					</view>
				</view>
			</scroll-view>
			<view class="tk-heard" v-if="list.children">
				<u-button type="primary" style="margin-right: 10px;" text="确认" class="btn" color="#82ECC3"
					@tap="StopImplement"></u-button>
				<u-button type="primary" text="取消" class="btn" color="#FF6E91" @tap="cancel"></u-button>
			</view>
		</view>

	</uni-popup>
</template>

<script>
	import {
		EmpInfo,
		EMR_Nursing_SaveOrderBU_NS1
	} from "@/api/user.js"
	import {
		mapMutations,
		mapState
	} from "vuex";
	import Select from '@/pages/ListOfPatients/selevt.vue'
	import dateTimePickerSync from '../../components/html/song-datetime-picker/song-datetime-picker.vue'
	import $moment from '../js/day.js'
	export default {
		props: {
			show: {
				type: Boolean,
				default: false
			},
			reportObj: {
				type: Object,
				default: {
					ordertype: ''
				}
			},
			reportShow: {
				type: Boolean
			},
			radiolist: {
				type: Array
			},
			teshuarray: {
				type: Array
			},

		},
		components: {
			Select,
			dateTimePickerSync
		},
		data() {
			return {
				// show2: true
				Lthegiht: '',
				value: '',
				value1: '',
				value2: '',
				value3: '',
				time: '',
				list: [],
				resuList: [],
				yuanyinValue: '',
				examinationTypeIndex: 0,
				textBled: true,
				putong_ady: '',
				yuanyinValue: false,
				yuanyin2: '',
				placeholder: '',
				putongkoufu: false,
				infoObj: {}
			}
		},
		computed: {
			...mapState('user', ["userInfo", "deleteObj", "scanningArray"]),
		},
		watch: {
			show(val) {
				if (val) {
					this.$refs.popup.open('center')
				} else {
					this.$refs.popup.close()
				}
			}
		},
		created() {

			this.placeholder = $moment().format('YYYY-MM-DD HH:mm:ss')
			this.EmpInfoFun()
			this.list = this.reportObj
			if (this.list?.children.length > 0) {
				this.list.children.map(item => {
					if (item.admission?.trim() == 'PO') {
						this.value = this.radiolist[0].name
						this.putongkoufu = true
					}
				})
			}

		},
		mounted() {
			if (this.show) {
				this.$refs.popup.open('center')
			} else {
				this.$refs.popup.close()
			}
		},
		methods: {
			async change(e) {
				try {
					if (e.split(" ").join("").length != 0) {
						const user = uni.getStorageSync('userInfo')
						const data = {
							HosKind: user.hoscode,
							empid: e
						}
						const res = await this.$http.EmpInfo(data)
						if (res[0]?.result == '1') {
							this.resuList = res
							this.value3 = res[0].name
							// return
						} else {
							this.value3 = res[0].result
						}
					}
				} catch (e) {
					uni.showToast({
						title: "执行异常！", //显示的文字
						duration: 3000, //显示多少时间，默认1500毫秒
						icon: "error", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
						mask: true
					})
				}

			},
			async EmpInfoFun() {
				const user = uni.getStorageSync('userInfo')
				console.log(user);
				const data = {
					HosKind: user.hoscode,
					empid: user.sUserid
				}
				const res = await this.$http.EmpInfo(data)
				if (res[0]?.result == '1') {
					this.infoObj = res[0]
				}
			},
			cancel() {
				uni.showModal({
					title: '提示',
					content: '是否取消用药?',
					success: (res) => {
						if (res.confirm) {
							this.$emit('cancelTails', false, this.reportObj.children, 'quxiao');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});

				// this.show2 = false
			},
			StopImplement() {
				let user = uni.getStorageSync('userInfo')
				if (this.radioVaule == 'mid' && this.putong_ady == 6 && this.yuanyin2.trim() == '') {
					uni.showToast({
						title: "您选择了未服药其他，请输入原因", //显示的文字
						duration: 2000, //显示多少时间，默认1500毫秒
						icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
						mask: true
					})
					return
				}
				if (this.placeholder == '' || this.placeholder == '请选择时间') {
					uni.showToast({
						title: "请先选择时间再确认！", //显示的文字
						duration: 2000, //显示多少时间，默认1500毫秒
						icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
						mask: true
					})
					return
				}
				if (this.value2 != '' && this.value3 != '') {
					// let arr = this.resuList.filter(item => {
					// 	return item.name == user.sUserid 
					// })
					if (this.value2 == user.sUserid) {
						uni.showToast({
							title: "输入工号与登入工号一致！", //显示的文字
							duration: 1500, //显示多少时间，默认1500毫秒
							icon: "error", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
							mask: true
						})
					} else {
						this.zhixingData(this.reportObj.children, this.placeholder)
						// this.$emit('cancelTails', false);
						console.log('执行医嘱');
					}
				} else {
					this.value2 = ''
					uni.showToast({
						title: "请输入工号！", //显示的文字
						duration: 1500, //显示多少时间，默认1500毫秒
						icon: "error", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
						mask: true
					})
				}
			},
			async zhixingData(obj, time) {
				try {

					let user = uni.getStorageSync('userInfo')
					// for (let i = 0; i < obj.length; i++) {
					// 	const data = {
					// 		HosKind: user.hoscode,
					// 		sExemode: 'PDA',
					// 		mrn: obj[i].mrn,
					// 		stay: 'I',
					// 		series: obj[i].series,
					// 		orderdordnarray: obj[i].orderdordn,
					// 		bedid: obj[i].bedid,
					// 		pname: obj[i].pname,
					// 		nschecker: obj[i].ns,
					// 		dodate: time,
					// 		operdept: user.HosKind,
					// 		operjp: user.sUserid,
					// 		iMark: obj[i].iMark,
					// 		iautocharge: obj[i].iautocharge,
					// 		exeflag3: this.yuanyin2
					// 	}
					// 	res = await this.$http.EMR_Nursing_SaveOrderBU_NS1(data)
					// }




					const promises = obj.map(async item => {
						let result = await this.$http.EMR_Nursing_SaveOrderBU_NS1({
							HosKind: user.hoscode,
							sExemode: 'PDA',
							mrn: item.mrn,
							stay: 'I',
							series: item.series,
							orderdordnarray: item.orderdordn,
							bedid: item.bedid,
							pname: item.pname,
							nschecker: this.value2, //item.ns
							dodate: time,
							operdept: user.HosKind,
							operjp: user.sUserid,
							iMark: item.iMark,
							iautocharge: item.iautocharge,
							exeflag3: this.yuanyin2
						})
						return result
					})
					const [res] = await Promise.all(promises);




					if (res[0].result == '1') {
						uni.showToast({
							title: "医嘱执行成功！", //显示的文字
							duration: 1000, //显示多少时间，默认1500毫秒
							icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none

						})
						this.$emit('cancelTails', false, this.reportObj.children, 'queren');
						// return
					} else {
						uni.showToast({
							title: res[0].result, //显示的文字
							duration: 2000, //显示多少时间，默认1500毫秒
							icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
							mask: true
						})
						this.$emit('cancelTails', false, this.list.children, 'shibai', res[0].result);
						// this.show2 = false
						return
					}
				} catch (e) {
					uni.showToast({
						title: '执行异常！', //显示的文字
						duration: 2000, //显示多少时间，默认1500毫秒
						icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
						mask: true
					})
					//TODO handle the exception
				}
			},
			radioChange(data) {
				this.radioVaule = data
				if (data == 'mid') {
					this.list.children[0].yuanyin2 = this.yuanyin2
					this.yuanyinValue = true
					this.examinationTypeIndex = 0
					this.yuanyin2 = this.teshuarray[this.examinationTypeIndex].label
				} else {
					this.yuanyinValue = false
					this.yuanyin2 = ''
				}
			},
			Selectchange(e) {
				this.putong_ady = e
				if (e == 6) {
					this.yuanyin2 = ''
					this.textBled = false
				} else {
					this.yuanyin2 = this.teshuarray[e].label
					this.textBled = true
				}
			},
			TimePicker(data, value) {
				this.placeholder = data
			},
			moveHandle() {}
		}
	}
</script>


<style scoped lang="scss">
	::v-deep .u-popup {
		.u-fade-enter-active {
			z-index: 99 !important;
		}
	}

	::v-deep.uni-popup {
		.uni-popup__wrapper {
			background-color: #fff !important;
		}
	}

	.xis-yuanyin {
		display: flex;
		align-items: center;
		height: 30px;
		margin: 0 6px;
		padding-bottom: 9px;

		.SelectList {
			width: 140px !important;
		}
	}

	.box-tk {
		// height: 212rpx;
		// background: #FFFFFF;
		border-radius: 8rpx;
		position: relative;
		padding-bottom: 15rpx;

		.view1 {
			font-size: 36rpx;
			font-family: SourceHanSansCN-Medium, SourceHanSansCN;
			font-weight: 500;
			color: #487bf4;
			line-height: 40px;
			text-align: center;
			display: flex;
			justify-content: space-evenly;
			align-items: center;

			.view1-title {
				color: #333333;

			}
		}

		.xian {
			position: absolute;
			width: 100%;
			height: 2rpx;
			background: #7AD9DF;
			left: 0;
			top: 80rpx;
			// opacity: 0.19;
			// opacity: 0.19;
			// margin: 14rpx 0;
		}

		.box-xis ::v-deep {
			width: 97%;
			// height: 92%;
			background: #B0E9EC;
			margin: 20rpx auto 0;
			padding-bottom: 12rpx;
			position: relative;
			border-radius: 12rpx;
			z-index: 99999;

			.uni-scroll-view {
				overflow: inherit !important;
			}

			.uni-scroll-view-content {
				width: 100% !important;
			}

			.box-img {
				position: absolute;
				right: 0;
				top: 0;
				width: 58px;
				height: 28px;
				background: url('../../static/img/coagulation.svg') no-repeat;
				background-size: 100% auto;
				box-shadow: 5px -3px 8px 0px #D4D9D9;
			}

			.xis-title {
				font-size: 16px;
				font-family: SourceHanSansCN-Normal, SourceHanSansCN;
				font-weight: 400;
				color: #333333;
				padding: 4rpx 18rpx;
				line-height: 28px;
				// height: 28px;
				width: 80%;
			}

			.xis-hend {
				// width: 303px;
				width: 96%;
				// height: calc(100%);
				// height: 81%;
				margin: 0 auto;
				// height: 228px;
				background: #F6FEFF;
				border-radius: 6px;
				opacity: 0.95;

				text {
					font-size: 32rpx;
					font-family: SourceHanSansCN-Medium, SourceHanSansCN;
					font-weight: 500;
					// color: #333333;
					line-height: 48rpx;
					// width: 66px;
					text-align: justify;
					text-align-last: justify;
				}

				.hend-title {
					font-size: 32rpx;
					font-family: SourceHanSansCN-Medium, SourceHanSansCN;
					// font-weight: 500;
					color: #333333;
					line-height: 48rpx;
					padding: 20rpx;
					display: flex;
					align-items: center;

					.text {
						width: 65px;
					}

					.hend-time {
						width: calc(100% - 65px);
					}
				}
			}
		}

		.tk-heard {
			display: flex;
			// height: calc(100% - 636rpx);
			align-items: center;
			margin: 16rpx auto 0;
			width: 97%;
		}

		.tk-heard ::v-deep {
			.u-button__text {
				font-size: 36rpx !important;
				font-family: SourceHanSansCN-Medium, SourceHanSansCN;
				font-weight: 500;
				color: #FFFFFF;
				line-height: 54rpx;
				letter-spacing: 28rpx;
			}
		}
	}

	::v-deep .u-radio__icon-wrap--circle {
		width: 26px !important;
		height: 26px !important;
		background-color: rgb(122, 217, 223) !important;
	}

	::v-deep .u-radio-group--row {
		justify-content: space-around;
	}

	.clao ::v-deep {
		.u-icon__icon {
			border-radius: 100%;
			background: #FEFF87;
			color: #FEFF87 !important;
			width: 13px !important;
			height: 13px !important;
			// font-size: 16px !important;
		}
	}

	.clat ::v-deep {
		.u-icon__icon {
			border-radius: 100%;
			background: #FFFFFF;
			// font-size: 16px !important;
			width: 13px !important;
			height: 13px !important;
		}
	}

	.box-text {
		padding: 7px !important;
	}

	.u-textarea::v-deep {
		.u-textarea__field {
			height: 100% !important;
		}

		.uni-textarea-wrapper {
			overflow: hidden !important;
		}
	}

	.box-aigicon {
		height: 320px;
	}
</style>
